<!--
 * @Author: 1243sd 782012816@qq.com
 * @Date: 2024-03-14 20:53:30
 * @LastEditors: 1243sd 782012816@qq.com
 * @LastEditTime: 2024-04-07 21:30:25
 * @FilePath: \frontend-ykt-admin\src\views\member\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!---- 会员列表 -----> 
<template>
    <div class="container">
        <b-card-new>
            <!-- <b-query-form-new ref="bForm" :data="formData" :form="dataForm.query" @search="handleSearch"></b-query-form-new> -->
            <b-query-table ref="bTable" :init-columns="initColumns()" :data-form="dataForm" :handleList="handleList"></b-query-table>
        </b-card-new>
        <!-- 添加和修改学校 -->
        <el-dialog :title="schoolForm.id?'编辑学校':'添加学校'" lock-scroll width="440px" :visible.sync="isSchool">
            <el-form label-width="80px">
                    <el-form-item label="学校名称:" required>
                        <el-input class="value" maxlength="10" v-model="schoolForm.name" placeholder="请输入真实姓名"></el-input>
                    </el-form-item>
                    <el-form-item label="是否启用:" required>
                        <el-radio-group v-model="schoolForm.status">
                            <el-radio :label="0">否</el-radio>
                            <el-radio :label="1">是</el-radio>
                        </el-radio-group>
                    </el-form-item>
            </el-form>
            
            <div slot="footer" class="dialog-footer">
                <b-button-new text="取消" @click="isSchool = false"></b-button-new>
                <b-button-new text="保存" @click="handleConfirm">确 定</b-button-new>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import mixinPageHeight from "@/mixinPageHeight"
export default {
    mixins:[mixinPageHeight],
    data() {
        return {
            formData:[
                { typeCode: "select", title: "用户类型", name: "user_type", 
                optionData: [
                    { key: '1', value: '平台' },
                    { key: '2', value: '站长' },
                    { key: '3', value: '商家' },
                    { key: '4', value: '用户' }
                    ] 
            },
            ],
            dataForm:{
                url: "api/school/list",
                query:{
                    user_type: "", // 用户类型(1.平台2.站长,3,商家.4.用户)
                }
            },
            // 学校信息弹窗
            isSchool:false,
            schoolForm: {
                id:'',
                name: '', // 学校名称
                status: 1, // 是否启用(0.否,1.是,默认1),示例值(1)
            },
            // 按钮
            handleList: [
                {
                    name: '添加',
                    btnCode: '',
                    btnClick: () =>  this.isSchool=true
                }
            ]
        }
    },
    created() {
       
    },
    methods:{
        // 添加和修改学校 
        editSchool(row){
            this.$api.school.details(row.id).then(res =>{
                this.schoolForm=res;
                this.isSchool=true
            })
        },
        // 改变积分 - 弹窗确定
        handleConfirm() {
                if (!this.schoolForm.name) {
                    this.$message.error('请输入学校名称')
                    return
                }
                var axiosName=this.schoolForm.id?'edit':'add';
               
                this.$api.school[axiosName](this.schoolForm).then(res => {
                    this.$message.success(this.schoolForm.id?'编辑成功':'添加成功');
                    this.schoolForm=this.$options.data().schoolForm;
                    this.isSchool = false
                    this.handleRefresh()
                })
        },
        initColumns() {
            return [
                { title:"学校名", valueName: "name" },
                { title:"是否启用", valueName: "status", customRander: (row) => ['否', '是'][row.status] },
                { title:"操作", fixed: 'right', width: 220, customRander: (row) => (
                    <BTableOperation list={
                        [
                            { name: '编辑', btnCode: '10', btnClick: () => this.editSchool(row)},
                            { name: '删除', btnCode: '9', btnClick: () => this.handleDel(row)},
                        ]
                        }></BTableOperation>
                    ),
                }
            ]
        },
        handleDel(row){
            this.$common.bconfirm("确定删除？", "提示").then(res => {
                this.$api.school.remove({id:row.id}).then(res => {
                    this.$message.success('删除成功')
                    this.$refs.bTable.reload();
                })
            })
        }
    }
}
</script>
<style lang="scss" scoped>
.d-flex{
    display: flex;
    align-items: center;
}
</style>